import Mock from 'mockjs'

var data1={};
var mdepartmentdata={};
var hospitaldata={};
var jhospitaldata={};
var nhospitaldata={};
var inquirydata={};
var packagedata={};
var regiondata={}


if(localStorage.getItem('user_list1')){
    data1=JSON.parse(localStorage.getItem('user_list1'))
}else{
    data1 = Mock.mock({
        "list|100":[
            {
                id:'@id',
                "order|+1":1,
                name:'@cname',
                'age|1-100':1,
                'sex|1':false,
                'phone|13000000000-19999999999':1,
                email:'@email',
                address:'@province(true)',
                "member|1":false,
                "money|100-1000":1,
            }
        ]
    })
    localStorage.setItem('user_list1',JSON.stringify( data1 ))
}

if(localStorage.getItem('hospital_list')){
    hospitaldata=JSON.parse(localStorage.getItem('hospital_list'))
}else{
    hospitaldata = Mock.mock({
        "list|10":[
            {
                "id|+1":1,
                address:'@city(true)'+'医院',
                "money|100-1000":1,
            }
        ]
    })
    localStorage.setItem('hospital_list',JSON.stringify( hospitaldata ))
}

if(localStorage.getItem('jhospital_list')){
    jhospitaldata=JSON.parse(localStorage.getItem('jhospital_list'))
}else{
    jhospitaldata = Mock.mock({
        "list|10":[
            {
                "id|+1":1,
                address:'@city(true)'+'医院',
                "money|100-1000":1,
            }
        ]
    })
    localStorage.setItem('jhospital_list',JSON.stringify( jhospitaldata ))
}


if(localStorage.getItem('nhospital_list')){
    nhospitaldata=JSON.parse(localStorage.getItem('nhospital_list'))
}else{
    nhospitaldata = Mock.mock({
        "list|10":[
            {
                "id|+1":1,
                address:'@city(true)'+'医院',
                "money|100-1000":1,
            }
        ]
    })
    localStorage.setItem('nhospital_list',JSON.stringify( nhospitaldata ))
}


if(localStorage.getItem('mdepartment_list')){
    mdepartmentdata=JSON.parse(localStorage.getItem('mdepartment_list'))
}else{
    mdepartmentdata = Mock.mock({
        "list":[
            {
                '皮肤科|1000000-5000000':1,
                '妇产科|1000000-5000000':1,
                '男科|1000000-5000000':1,
                '儿科|1000000-5000000':1,
                '中医科|1000000-5000000':1,
                '内科|1000000-5000000':1,
                '外科|1000000-5000000':1,
                '眼科|1000000-5000000':1,
                '口腔科|1000000-5000000':1,
                '骨科|1000000-5000000':1,
                '传染科|1000000-5000000':1,
                '体检科|1000000-5000000':1,
            },
            {
                '皮肤科|10000000-50000000':1,
                '妇产科|10000000-50000000':1,
                '男科|10000000-50000000':1,
                '儿科|10000000-50000000':1,
                '中医科|10000000-50000000':1,
                '内科|10000000-50000000':1,
                '外科|10000000-50000000':1,
                '眼科|10000000-50000000':1,
                '口腔科|10000000-50000000':1,
                '骨科|10000000-50000000':1,
                '传染科|10000000-50000000':1,
                '体检科|10000000-50000000':1,
            },
            {
                '皮肤科|3000000-15000000':1,
                '妇产科|3000000-15000000':1,
                '男科|3000000-15000000':1,
                '儿科|3000000-15000000':1,
                '中医科|3000000-15000000':1,
                '内科|3000000-15000000':1,
                '外科|3000000-15000000':1,
                '眼科|3000000-15000000':1,
                '口腔科|3000000-15000000':1,
                '骨科|3000000-15000000':1,
                '传染科|3000000-15000000':1,
                '体检科|3000000-15000000':1,
            }
        ]
    })
    localStorage.setItem('mdepartment_list',JSON.stringify( mdepartmentdata ))
}


if(localStorage.getItem('inquiry_list')){
    inquirydata=JSON.parse(localStorage.getItem('inquiry_list'))
}else{
    inquirydata = Mock.mock({
        "list|2":[
            {
                '皮肤科|100-500':1,
                '妇产科|100-500':1,
                '男科|100-500':1,
                '儿科|100-500':1,
                '中医科|100-500':1,
                '内科|100-500':1,
                '外科|100-500':1,
                '眼科|100-500':1,
                '口腔科|100-500':1,
                '骨科|100-500':1,
                '传染科|100-500':1,
                '体检科|100-500':1,
            },
            {
                '皮肤科|1000-3000':1,
                '妇产科|1000-3000':1,
                '男科|1000-3000':1,
                '儿科|1000-3000':1,
                '中医科|1000-3000':1,
                '内科|1000-3000':1,
                '外科|1000-3000':1,
                '眼科|1000-3000':1,
                '口腔科|1000-3000':1,
                '骨科|1000-3000':1,
                '传染科|1000-3000':1,
                '体检科|1000-3000':1,
            },
            {
                '皮肤科|300-1500':1,
                '妇产科|300-1500':1,
                '男科|300-1500':1,
                '儿科|300-1500':1,
                '中医科|300-1500':1,
                '内科|300-150':1,
                '外科|300-1500':1,
                '眼科|300-1500':1,
                '口腔科|300-1500':1,
                '骨科|300-1500':1,
                '传染科|300-1500':1,
                '体检科|300-1500':1,
            }
        ]
    })
    localStorage.setItem('inquiry_list',JSON.stringify( inquirydata ))
}

if(localStorage.getItem('package_list')){
    packagedata=JSON.parse(localStorage.getItem('package_list'))
}else{
    packagedata = Mock.mock({
        "list|3":[
            {
                "p1|0-1000":1,
                "p2|0-1000":1,
                "p3|0-1000":1,
                "p4|0-1000":1,
                "p5|0-1000":1,
            }
        ]
    })
    localStorage.setItem('package_list',JSON.stringify( packagedata ))
}

if(localStorage.getItem('region_list')){
    regiondata=JSON.parse(localStorage.getItem('region_list'))
}else{
    regiondata = Mock.mock({
        "list|15":[
            {
                "r1|0-1000":1,
                "r2|0-1000":1,
                "r3|0-1000":1,
                "r4|0-1000":1,
                "r5|0-1000":1,
                "r6|0-1000":1,
            }
        ]
    })
    localStorage.setItem('region_list',JSON.stringify( regiondata ))
}


Mock.mock('/api/region/list','get',()=>{  
    //返回数据
    return regiondata;
})

Mock.mock('/api/package/list','get',()=>{  
    //返回数据
    return packagedata;
})

Mock.mock('/api/user/list','get',()=>{  
    //返回数据
    return data1;
})
Mock.mock('/api/mdepartment/list','get',()=>{  
    //返回数据
    return mdepartmentdata;
})
Mock.mock('/api/hospital/list','get',()=>{  
    //返回数据
    return hospitaldata;
})
Mock.mock('/api/jhospital/list','get',()=>{  
    //返回数据
    return jhospitaldata;
})
Mock.mock('/api/nhospital/list','get',()=>{  
    //返回数据
    return nhospitaldata;
})
Mock.mock('/api/inquiry/list','get',()=>{  
    //返回数据
    return inquirydata;
})
Mock.mock('/api/dellist/list','post',(req)=>{
    var{id}=JSON.parse(req.body);
    var i=data1.list.findIndex((item)=>{
        return item.order==id;
    })
    if(i!=-1){
        data1.list.splice(i,1);
        localStorage.setItem('user_list1',JSON.stringify( data1 ));
    }
    return {status:200,msg:'删除成功!',list:data1.list}
})
Mock.mock('/api/edititem/list','post',(req)=>{
    var item=JSON.parse(req.body);
    var itemm=item.form._value
    var i=data1.list.findIndex((it)=>{
        return it.order==itemm.order;
    })
    if(i!=-1){
        data1.list[i]=itemm;
        localStorage.setItem('user_list1',JSON.stringify( data1 ));
    }
})

Mock.mock('/api/search/list','post',(req)=>{
    
    var item=JSON.parse(req.body);
    // console.log(data.list.length);
    for(var j=0;j<data1.list.length;j++){
        if(data1.list[j].name==item.search){
            console.log(data1.list[j]);
            return data1.list[j]
        }
    }
})
